<?php


abstract class BaseCountries extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $iso_3166_alpha2;


	
	protected $iso_3166_alpha3;


	
	protected $iso_3166_numeric;


	
	protected $fips;


	
	protected $country;


	
	protected $capital;


	
	protected $area_km;


	
	protected $population;


	
	protected $continent;


	
	protected $id;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getIso3166Alpha2()
	{

		return $this->iso_3166_alpha2;
	}

	
	public function getIso3166Alpha3()
	{

		return $this->iso_3166_alpha3;
	}

	
	public function getIso3166Numeric()
	{

		return $this->iso_3166_numeric;
	}

	
	public function getFips()
	{

		return $this->fips;
	}

	
	public function getCountry()
	{

		return $this->country;
	}

	
	public function getCapital()
	{

		return $this->capital;
	}

	
	public function getAreaKm()
	{

		return $this->area_km;
	}

	
	public function getPopulation()
	{

		return $this->population;
	}

	
	public function getContinent()
	{

		return $this->continent;
	}

	
	public function getId()
	{

		return $this->id;
	}

	
	public function setIso3166Alpha2($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->iso_3166_alpha2 !== $v) {
			$this->iso_3166_alpha2 = $v;
			$this->modifiedColumns[] = CountriesPeer::ISO_3166_ALPHA2;
		}

	} 
	
	public function setIso3166Alpha3($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->iso_3166_alpha3 !== $v) {
			$this->iso_3166_alpha3 = $v;
			$this->modifiedColumns[] = CountriesPeer::ISO_3166_ALPHA3;
		}

	} 
	
	public function setIso3166Numeric($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->iso_3166_numeric !== $v) {
			$this->iso_3166_numeric = $v;
			$this->modifiedColumns[] = CountriesPeer::ISO_3166_NUMERIC;
		}

	} 
	
	public function setFips($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->fips !== $v) {
			$this->fips = $v;
			$this->modifiedColumns[] = CountriesPeer::FIPS;
		}

	} 
	
	public function setCountry($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->country !== $v) {
			$this->country = $v;
			$this->modifiedColumns[] = CountriesPeer::COUNTRY;
		}

	} 
	
	public function setCapital($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->capital !== $v) {
			$this->capital = $v;
			$this->modifiedColumns[] = CountriesPeer::CAPITAL;
		}

	} 
	
	public function setAreaKm($v)
	{

		if ($this->area_km !== $v) {
			$this->area_km = $v;
			$this->modifiedColumns[] = CountriesPeer::AREA_KM;
		}

	} 
	
	public function setPopulation($v)
	{

		if ($this->population !== $v) {
			$this->population = $v;
			$this->modifiedColumns[] = CountriesPeer::POPULATION;
		}

	} 
	
	public function setContinent($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->continent !== $v) {
			$this->continent = $v;
			$this->modifiedColumns[] = CountriesPeer::CONTINENT;
		}

	} 
	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = CountriesPeer::ID;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->iso_3166_alpha2 = $rs->getString($startcol + 0);

			$this->iso_3166_alpha3 = $rs->getString($startcol + 1);

			$this->iso_3166_numeric = $rs->getInt($startcol + 2);

			$this->fips = $rs->getString($startcol + 3);

			$this->country = $rs->getString($startcol + 4);

			$this->capital = $rs->getString($startcol + 5);

			$this->area_km = $rs->getFloat($startcol + 6);

			$this->population = $rs->getFloat($startcol + 7);

			$this->continent = $rs->getString($startcol + 8);

			$this->id = $rs->getInt($startcol + 9);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 10; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Countries object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(CountriesPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			CountriesPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(CountriesPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = CountriesPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += CountriesPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = CountriesPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = CountriesPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getIso3166Alpha2();
				break;
			case 1:
				return $this->getIso3166Alpha3();
				break;
			case 2:
				return $this->getIso3166Numeric();
				break;
			case 3:
				return $this->getFips();
				break;
			case 4:
				return $this->getCountry();
				break;
			case 5:
				return $this->getCapital();
				break;
			case 6:
				return $this->getAreaKm();
				break;
			case 7:
				return $this->getPopulation();
				break;
			case 8:
				return $this->getContinent();
				break;
			case 9:
				return $this->getId();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = CountriesPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getIso3166Alpha2(),
			$keys[1] => $this->getIso3166Alpha3(),
			$keys[2] => $this->getIso3166Numeric(),
			$keys[3] => $this->getFips(),
			$keys[4] => $this->getCountry(),
			$keys[5] => $this->getCapital(),
			$keys[6] => $this->getAreaKm(),
			$keys[7] => $this->getPopulation(),
			$keys[8] => $this->getContinent(),
			$keys[9] => $this->getId(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = CountriesPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setIso3166Alpha2($value);
				break;
			case 1:
				$this->setIso3166Alpha3($value);
				break;
			case 2:
				$this->setIso3166Numeric($value);
				break;
			case 3:
				$this->setFips($value);
				break;
			case 4:
				$this->setCountry($value);
				break;
			case 5:
				$this->setCapital($value);
				break;
			case 6:
				$this->setAreaKm($value);
				break;
			case 7:
				$this->setPopulation($value);
				break;
			case 8:
				$this->setContinent($value);
				break;
			case 9:
				$this->setId($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = CountriesPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setIso3166Alpha2($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setIso3166Alpha3($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setIso3166Numeric($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setFips($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCountry($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setCapital($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setAreaKm($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setPopulation($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setContinent($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setId($arr[$keys[9]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(CountriesPeer::DATABASE_NAME);

		if ($this->isColumnModified(CountriesPeer::ISO_3166_ALPHA2)) $criteria->add(CountriesPeer::ISO_3166_ALPHA2, $this->iso_3166_alpha2);
		if ($this->isColumnModified(CountriesPeer::ISO_3166_ALPHA3)) $criteria->add(CountriesPeer::ISO_3166_ALPHA3, $this->iso_3166_alpha3);
		if ($this->isColumnModified(CountriesPeer::ISO_3166_NUMERIC)) $criteria->add(CountriesPeer::ISO_3166_NUMERIC, $this->iso_3166_numeric);
		if ($this->isColumnModified(CountriesPeer::FIPS)) $criteria->add(CountriesPeer::FIPS, $this->fips);
		if ($this->isColumnModified(CountriesPeer::COUNTRY)) $criteria->add(CountriesPeer::COUNTRY, $this->country);
		if ($this->isColumnModified(CountriesPeer::CAPITAL)) $criteria->add(CountriesPeer::CAPITAL, $this->capital);
		if ($this->isColumnModified(CountriesPeer::AREA_KM)) $criteria->add(CountriesPeer::AREA_KM, $this->area_km);
		if ($this->isColumnModified(CountriesPeer::POPULATION)) $criteria->add(CountriesPeer::POPULATION, $this->population);
		if ($this->isColumnModified(CountriesPeer::CONTINENT)) $criteria->add(CountriesPeer::CONTINENT, $this->continent);
		if ($this->isColumnModified(CountriesPeer::ID)) $criteria->add(CountriesPeer::ID, $this->id);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(CountriesPeer::DATABASE_NAME);

		$criteria->add(CountriesPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setIso3166Alpha2($this->iso_3166_alpha2);

		$copyObj->setIso3166Alpha3($this->iso_3166_alpha3);

		$copyObj->setIso3166Numeric($this->iso_3166_numeric);

		$copyObj->setFips($this->fips);

		$copyObj->setCountry($this->country);

		$copyObj->setCapital($this->capital);

		$copyObj->setAreaKm($this->area_km);

		$copyObj->setPopulation($this->population);

		$copyObj->setContinent($this->continent);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new CountriesPeer();
		}
		return self::$peer;
	}

} 